﻿using B.S.DataBase.MyProject.Domain.Infrastructures;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure;
using MediatR;
using MedicalPCTerminal.Read.API.Appcation.Commands.FoundationCommand;

namespace MedicalPCTerminal.Read.API.Appcation.CommandHandlers.FoundationCommandHanlder
{
    /// <summary>
    /// 查询慢病指标命令处理
    /// </summary>
    public class GetDiseaseIndicatorsCommandHandler : IRequestHandler<GetDiseaseIndicatorsCommand, APIResult<List<DiseaseIndicators>>>
    {
        /// <summary>
        /// SqlSugar
        /// </summary>
        private readonly SqlSugarContext sqlSugar;
        /// <summary>
        /// 构造方法
        /// </summary>
        public GetDiseaseIndicatorsCommandHandler(SqlSugarContext sqlSugar)
        {
            this.sqlSugar = sqlSugar;
        }
        /// <summary>
        /// 处理
        /// </summary>
        /// <param name="request">请求</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns></returns>
        public Task<APIResult<List<DiseaseIndicators>>> Handle(GetDiseaseIndicatorsCommand request, CancellationToken cancellationToken)
        {
            try
            {
                APIResult<List<DiseaseIndicators>> result = new APIResult<List<DiseaseIndicators>>();
                var list = sqlSugar.db.Queryable<DiseaseIndicators>().Where(x => x.IndicatorsName == request.IndicatorsName && x.IsDel == false);
                list = list.OrderByDescending(x => x.IndicatorsId);
                result.Code = APIEnum.查询成功;
                result.Msg = APIEnum.查询成功.ToString();
                result.data = list.ToList();
                return Task.FromResult(result);
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
